import orderApi from "../api/order";
import shopGoodsApi from "../api/shopGoods"
import storesApi from "../api/stores"
export default {
    namespaced: true,
    state: {
        curpage: 1,
        eachPage: 3,
        total: 0,
        maxPage: 0,
        rows: [],
        goodsrows: [],
        storesrows: [],
        distributionrows: []
    },
    mutations: {
        get(state, order) {
            Object.assign(state, order)
        },
        getgoods(state, order) {
            state.goodsrows = order.rows
        },
        getstores(state, order) {
            state.storesrows = order.rows
        },
        getDistribution(state, data) {
            if (data.length) {
                state.distributionrows = data;
            } else {
                state.distributionrows = "";
            }
        },
        queryList(state, order) {
            console.log(order);
            state.rows = order
            console.log(state.rows);
        },
        setCurPage(state, curPage) {
            console.log();
            state.curpage = curPage;
        },

    },
    actions: {
        get: async ({ state, commit }) => {
            const { curpage, eachPage } = state;
            const data = await orderApi.get(curpage, eachPage);
            commit("get", data)
        },
        getgoods: async ({ state, commit }) => {
            const { curpage, eachPage } = state;
            const data = await shopGoodsApi.get(curpage, eachPage);
            commit("getgoods", data)
        },
        getstores: async ({ state, commit }) => {
            const { curpage, eachPage } = state;
            const data = await storesApi.get(curpage, eachPage);
            commit("getstores", data)
        },
        getDistrbution: async ({ commit }, id) => {
            const data = await orderApi.getDistribution(id);
            console.log(data);
            commit("getDistribution", data);
        },
        sendOrder: async ({ state }, data) => {
            console.log(state);
            console.log(data);
            await orderApi.addOrders(data);
        },
        searchOrder: async ({ commit }, { searchID }) => {
            const data = await orderApi.searchOrder(searchID);
            commit("queryList", data);
        },
    }
}
